import FairyEditor = CS.FairyEditor;
var App = FairyEditor.App;

/**
 * @description 组件主界面页签-包名后缀
 * @author hongen.gao
 */
export class DocTabSuffix {
    public add(): void {
        this.suffix();
        App.libView.onClick.Set(this.suffix.bind(this));
    }

    private suffix(): void {
        const comp = App.docView.GetChildAt(0).asCom;
        const tabs = comp.GetChild('tabs').asCom;

        for (let i = 0; i < tabs.numChildren; i++) {
            const tab = tabs.GetChildAt(i).asButton;
            const url = tab.name;
            const packageItem = App.project.GetItemByURL(url);
            const title = tab.title.split('@')[0];
            tab.title = `${title}@${packageItem.owner.name}`;
        }
    }
}